using System;
using System.Runtime.InteropServices;

namespace SpellCore
{
    public class SimilarityCheckResult : ISimilarityCheckResult
    {
        private int _score;
        private string _word;

        public SimilarityCheckResult(int score, string word)
        {
            _score = score;
            if(_score < UnknownScore)
            {
                throw new ArgumentException("score must be greater than or equal to 0 or Unknown");
            }
            if(string.IsNullOrEmpty(word))
            {
                throw new ArgumentException("word must not be empty or null");
            }
            _word = word;
        }

        public const int UnknownScore = -1;

        // need to define semantics of score
        [ComVisible(true)]
        public int SimilarityScore
        {
            get { return _score; }
        }

        [ComVisible(true)]
        public string Word
        {
            get { return _word; }
        }

        [ComVisible(false)]
        public override bool Equals(object obj)
        {
            SimilarityCheckResult scr = (SimilarityCheckResult) obj;
            if (scr == null || 
                !scr.Word.Equals(Word) || 
                !scr.SimilarityScore.Equals(SimilarityScore))
            {
                return false;
            }
            return true;
        }

        [ComVisible(false)]
        public override int GetHashCode()
        {
            return Word.GetHashCode() ^ SimilarityScore.GetHashCode();
        }
    }
}